# import sys
# sys.path.append("/home/yyt/nfshare/yolov8/")
from ultralytics import YOLO

# Create a new YOLO model from scratch
# model = YOLO('/home/yyt/nfshare/yolov8/ultralytics/cfg/models/v8/yolov8.yaml')

# Load a pretrained YOLO model (recommended for training)
model = YOLO('D:/pythonProject/weed_detaction/ultralytics-main/ultralytics/cfg/models/v8/yolov8-Linear-ATT.yaml')

# Train the model using the 'coco128.yaml' dataset for 3 epochs
results = model.train(data="../datasets/weeds/my_data.yaml",
                      imgsz=640,  # 输入图像的大小为整数或 w,h
                      epochs=10,  # 要训练的次数
                      batch=2,  # 每批次的图像数量（AutoBatch 为 -1）
                      device="cpu",  # 要运行的设备，即 cuda device=0 或 device=0,1,2,3 或 device=cpu
                      workers=2,  # 用于数据加载的工作线程数（如果是 DDP，则为每个 RANK）
                      lr0=0.01,
                      resume=False,
                      amp=False,
                      val=True)

# Evaluate the model's performance on the validation set
# results = model.val(data='/home/yyt/nfshare/yolov8/ultralytics/cfg/datasets/hr.yaml',amp=False,epochs=2,batch=8)

success = model.export(format='onnx')